package cn.cvs.mapper;

import cn.cvs.pojo.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Insert(" INSERT INTO `crm`.`sys_user`( `usr_name`, `usr_password`, `usr_role_id`, `usr_flag`) " +
            "        VALUES ( #{usrName},  #{usrPassword}, #{usrRoleId}, #{usrFlag})")
    public void insert(SysUser user );


    @Select(" select  `usr_id`,  `usr_name`, `usr_password`, `usr_role_id`, `usr_flag` from `crm`.`sys_user` ")
    @Results(id="rs_usr",value = {
            @Result(column="usr_Id"      ,property="usrId"      ),
            @Result(column="usr_name"    ,property="usrName"    ),
            @Result(column="usr_password",property="usrPassword"),
            @Result(column="usr_role_id" ,property="usrRoleId"  ),
            @Result(column="usr_flag"    ,property="usrFlag"    )
    })
    List<SysUser> findAll();

    @Select(" select  `usr_id`,  `usr_name`, `usr_password`, `usr_role_id`, `usr_flag` " +
            " from `crm`.`sys_user` " +
            " where usr_name=#{userName} ")
    @ResultMap("rs_usr")
    SysUser findByUsrName(@Param("userName") String userName);


    @Select("select  `usr_id`,  `usr_name`, `usr_password`, `usr_role_id`, `usr_flag`" +
            "        ,r.role_id,r.role_name,r.role_flag,r.role_desc" +
            "        from `crm`.`sys_user` u,sys_role r" +
            "        where 1=1" +
            "        and u.usr_role_id=r.role_id" +
            "        and u.usr_name=#{userName}")
    @Results(
            id="rs_usr_role",value = {
            @Result(column="usr_Id"      ,property="usrId"      ),
            @Result(column="usr_name"    ,property="usrName"    ),
            @Result(column="usr_password",property="usrPassword"),
            @Result(  column="usr_role_id" ,property="usrRoleId" ),
            @Result(column="usr_flag"    ,property="usrFlag"    ),
            @Result(column="role_id"    ,property="sysRole"
                    ,one=@One(select=("cn.cvs.mapper.RoleMapper.getRoleById")))
            }
    )
    SysUser findRoleByUsrName(@Param("userName") String userName);


}
